package com.yskj.mwk.utils;

import java.util.regex.Pattern;

public class EnhancedPhoneUtils {
    // 支持国际号码（示例：香港8位、美国10位）
    private static final Pattern INTERNATIONAL_PATTERN =
            Pattern.compile("^(\\+?852\\d{8})|(\\+?1\\d{10})|(1[3-9]\\d{9})$");

    public String enhancedMask(String phone) {
        if (phone == null) return null;

        // 移除所有非数字字符（保留+号）
        String cleaned = phone.replaceAll("[^+\\d]", "");

        if (!INTERNATIONAL_PATTERN.matcher(cleaned).matches()) {
            return null;
        }

        // 根据国家/地区处理脱敏
        if (cleaned.startsWith("+852")) {
            return cleaned.substring(0, 4) + "****" + cleaned.substring(6);
        } else if (cleaned.startsWith("+1")) {
            return cleaned.substring(0, 3) + "***" + cleaned.substring(6);
        } else {
            return cleaned.substring(0, 3) + "****" + cleaned.substring(7);
        }
    }
}
